<?php
/**
 * LoveScoreLogService.php
 * 文件描述 恩爱值账户记录
 * Created on 2020/8/31 18:35
 * Created by 刘小龙 595929049@qq.com
 */

namespace app\xiangji\services;



use app\common\models\LoveScore;

class LoveScoreLogService
{
    public function __construct()
    {
    }

    /**
     * @todo 记录恩爱值日志
     * @param LoveScore $score
     * @param int $change
     * @param string $scene
     * @return false|\think\Model
     */
    public static function addScoreLog(LoveScore $score, int $change, string $scene = '签到奖励')
    {
        return $score->logs()->save([
            'user_id'   => $score->user_id,
            'change'    => $change,
            'scene'     => $scene,
            'before_score'  => $score->total_score,
            'after_score'   => $score->total_score + $change
        ]);
    }
}
